<template>


<div style="border: solid skyblue 3px ;width: 400px;height: 200px;margin: auto;">
  <div v-if="code.file!==undefined ">
    <div style="height: 50px;" ></div>
    <div style="width: fit-content;margin: 0 auto">此文件由 {{code.file.user.uname}}分享:</div>
    <el-row style="width: fit-content;margin: 2% auto">
      <div style="height: 50px"></div>
      <el-button type="primary" size="mini" :disabled="!code" @click="downloadBycode">下载</el-button>
      <el-button size="mini" @click="$router.replace('/')">返回网盘首页</el-button>
    </el-row>
  </div>
  <div v-else style="width: fit-content;margin: 0 auto">
    <h2 style="width: fit-content;margin: 0">分享已被取消或文件被删除</h2>
    <el-button size="mini" @click="$router.replace('/')">返回网盘首页</el-button>
  </div>
</div>
</template>

<script>
import ImageViewer from "./ImageViewer";
export default {
  name: "Share",
  components: {ImageViewer},
  data(){
    return{
      code:{
        //测试用例
        // shareTime:'2022-08-10 14:22:30',
        // activeCode:'',
        // file:{
        //   fid:1,
        //   fName:'1.jpg',
        //   user:{
        //     uname:'hapehape'
        //   }
        // }
      }
    }
  },
  methods:{
    getCode(){
      this.axios.get(this.baseUrl+"file/getCode",{
        params:{
          code:this.$route.query.code
        }
      }).then(res=>{
        this.code = res.data;
      })
    },
    downloadBycode(){
      location.href = this.baseUrl+"download/code/"+this.$route.query.code;
      if(this.code.file.isDir===1){
        this.$message.info("下载将在压缩包构建完毕后开始");
      }
    }
  },
  mounted() {
    this.getCode();
  }
}
</script>

<style scoped>

</style>
